<template>
 <div>
    <!-- 顶部栏 -->
    <van-nav-bar
      :title="$route.query.q"
      left-arrow
      @click-left="$router.back()"
    />
    <!-- 搜索结果 -->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" :key="item.art_id" :title="item.title" 
      @click="$router.push({path:'/article',query:{id:item.art_id}})"
      />
    </van-list>
  </div>
</template>

<script>
//导入接口
import {getSearch} from './home'
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page:1
    };
  },
  methods: {
     async onLoad() {
      // 请求数据
      let res = await getSearch({
          page:this.page,
          q:this.$route.query.q
      })
      console.log(res);
    //   绑定数据
    this.list.push(...res.data.data.results)
    // 页码自增
    this.page++
    // 关闭动画
    this.loading = false
    // 判断是否加载完成(服务器给你一个空数组)
    if(res.data.data.results.length == 0){
        this.finished = true
    }
      
    },
  },
};
</script>
  
<style>

</style>